<?php
namespace Ucmaim\Model;
use Think\Model;


class MoneyLogModel extends Model{

    // 获取交易流水列表
    public function get($uid, $search){
        $this->alias('A');
        $map['log_master_id'] = $uid;
        if( is_array($search) && !empty($search) ){
            $map = array_merge($map, $search);
        }
        $this->field('A.*, B.member_name AS seller_name, B.member_mobile AS mobile');
        $this->join('uc_member B on A.log_slave_id = B.member_id');
        $this->order('A.log_time desc');
        return $this->where($map)->select();
    }

    // 生成一条记录
    public function makeLog($master, $slave, $amount, $order_sn, $pay_sn, $remark = ''){
        $time = time();
        $data['log_master_id'] = $master;
        $data['log_slave_id'] = $slave;
        $data['log_amount'] = $amount;
        $data['order_sn'] = $order_sn;
        $data['log_paysn'] = $pay_sn;
        $data['log_time'] = $time;
        $data['log_remark'] = $remark;
        if( $this->create($data) ){
            $this->add();
            return true;
        }else{
            return false;
        }
    }
}